﻿<?php
$email=trim(@$_POST["email"]);
$key=trim(@$_POST["key"]);
$partner=trim(@$_POST["partner"]);
if ($email!="" && $key!="" && $partner!=""){
	echo savepayinfo($email,$key,$partner);
} 


function getconn(){
	$conn=mysql_connect('210.209.76.30:3306','zfupay','zfupay@#123456');
	mysql_select_db('zfupay');
	return $conn;
}

//客户的付款资料
function savepayinfo($email,$key,$partner){
	$conn=getconn();
	$sql="update test_account set email='".trim($email)."',apikey='".trim($key)."',partner='".trim($partner)."' where username='guest'";
	$result=mysql_query($sql);
	//if (mysql_affected_rows($result)==1){
	mysql_close($conn);
	return "ok";
	//}
}

function  updateloginnum(){
	$conn=getconn();
	$sql="select loginnum from test_account where username='guest'";
	$result=mysql_query($sql);
	$loginnum=mysql_result($result, 0);
	$sql2="update test_account set loginnum='".($loginnum+1)."' where username='guest'";
	mysql_query($sql2);
	mysql_close($conn);
}

function getbalance(){
	$conn=getconn();
	$sql="select balance from test_account where username='guest'";
	$result=mysql_query($sql);
	//odbc_fetch_row($result);
	$balance=mysql_result($result, 0);
	mysql_close($conn);
	return  $balance;
}

function savelist($title,$payAmount){
	$conn=getconn();
	$sql=
"insert into test_orderlist(time,trsno,channel,states,price) 
	values('".date("Y.m.d H:m:s")."','".substr($title, 3)."','支付宝在线充值','未入账','".$payAmount."')";
	mysql_query($sql);
	
	mysql_close($conn);
}

function  getpayinfo(){
	$conn=getconn();
	$sql="select email,apikey,partner from test_account where username='guest'";
	$result=mysql_query($sql);
	$payinfo['seller_email']=mysql_result($result, 0,"email");
	$payinfo['key']=mysql_result($result, 0,"apikey");
	$payinfo['partner']=mysql_result($result, 0,"partner");
	mysql_close($conn);
	return  $payinfo;
}

function updatestates($out_trade_no,$trade_amount){
		$conn=getconn();
		$sql="update test_orderlist set states='充值成功' where trsno='".$out_trade_no."'";
		$result=mysql_query($sql);
		mysql_close($conn);
		
}

function setbalance($trade_amount){
		$conn=getconn();
		$sql="update test_account set balance='".($trade_amount+getbalance())."' where username='guest'";
		mysql_query($sql);
		
		mysql_close($conn);
}

?>